var COS = require('cos-js-sdk-v5');
import AuthUser from '@/api/model/users';

const uploadFile = async (file: any) => {
    const res = await AuthUser.GetOss();
    const type = file.fileInstance.type;
    const fileObject = new Blob([file.fileInstance], {type});
    const cos = new COS({...res.data});
    const {Location} = await cos.putObject({
        domain: 'https://technique-1251242649.cos.ap-beijing.myqcloud.com',
        Bucket: 'technique-1251242649' /* 填入您自己的存储桶，必须字段 */,
        Region: 'ap-beijing' /* 存储桶所在地域，例如ap-beijing，必须字段 */,
        Key:
            `${type}/` +
            file.name /* 存储在桶里的对象键（例如1.jpg，a/b/test.txt），必须字段 */,
        StorageClass: 'STANDARD',
        Body: fileObject, // 上传文件对象
    });
    return '//' + Location;
};

export default uploadFile;
